
package com.tinckay.common.log.factory;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.tinckay.common.constant.LogType;
import com.tinckay.common.util.SpringContextHolder;
import com.tinckay.entity.po.SysLog;
import com.tinckay.entity.po.User;

/**
 * 日志对象创建工厂
 *
 * @author yuanjie
 */
public class LogFactory {

    private static ObjectMapper mapper = SpringContextHolder.getBean(ObjectMapper.class);

    /**
     * 创建系统日志
     */
    public static SysLog createSysLog(LogType logType, User user, String operation, Long time, String methodName, String params, String ip) {
        SysLog sysLog = new SysLog();
        sysLog.setUserId(user.getId());
        sysLog.setUsername(user.getName());
        sysLog.setOperation(operation);
        sysLog.setTime(time);
        sysLog.setMethod(methodName);
        sysLog.setParams(params);
        sysLog.setIp(ip);
        sysLog.setLogType((byte) logType.getCode());
        //sysLog.setLocation(AddressUtils.getRealAddressByIP(sysLog.getIp(), mapper));
        return sysLog;
    }
}
